﻿package queue;

import java.util.*; 

public class ArrayListLinkedListTest { 
      public static void main(String args[]) { 
            // 추가할 데이터의 개수를 고려하여 충분히 잡아야한다.
            LinkedList ll = new LinkedList(); 
            Queue ll2 = new LinkedList(); 

            System.out.println(); 
            System.out.println("= addLast, removeFirst 순차적으로 삭제하기 ="); 
            System.out.println("addLast :"+add1(ll)); 
            System.out.println("removeFirst :"+remove1(ll));
            
            
            System.out.println(); 
            System.out.println("= offer, poll 순차적으로 삭제하기 ="); 
            System.out.println("offer :"+add3(ll2)); 
            System.out.println("poll :"+remove3(ll2)); 
            
            
            
      } 

      public static long add1(LinkedList list) { 
            long start = System.currentTimeMillis(); 
            for(int i=0; i<200000;i++) list.addLast(""+i+"X"); 
            long end = System.currentTimeMillis(); 
            return end - start; 
      } 

      public static long remove1(LinkedList list) { 
            long start = System.currentTimeMillis(); 
            for(int i=0; i<200000;i++) list.removeFirst(); 
            long end = System.currentTimeMillis(); 
            return end - start; 
      } 

      public static long add3(Queue list){
          long start = System.currentTimeMillis(); 
          for(int i=0; i<200000;i++) list.offer(""+i+"X"); 
          long end = System.currentTimeMillis(); 
          return end - start; 
      }
      
      public static long remove3(Queue list) { 
          long start = System.currentTimeMillis(); 
          for(int i=0; i<200000;i++) list.poll(); 
          long end = System.currentTimeMillis(); 
          return end - start; 
    }
      
} 
